package com.swt.testdemo.controller;

import com.swt.testdemo.config.ResponseBean;
import com.swt.testdemo.config.ResponseMessage;
import com.swt.testdemo.form.EditEntityForm;
import com.swt.testdemo.service.SysOntologyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020/11/13 10:13
 **/
@RestController
@RequestMapping("/sys/ontology")
@Api(tags = "后台管理--本体关系管理")
@Slf4j
public class SysOntologyController {

    @Autowired
    private SysOntologyService sysOntologyService;







    @ApiOperation("01 获取实体列表")
    @GetMapping(value = "/entity-list")
    public ResponseEntity<ResponseBean> getEntityList(){
        ResponseBean response = sysOntologyService.getEntityList();
        return ResponseEntity.status(response.getStatus()).body(response);
    }

    @ApiOperation("02 获取实体信息")
    @GetMapping("/entity-info")
    @ApiImplicitParam(name = "entityId", value = "实体id", paramType = "query", dataType = "int", defaultValue = "1")
    public ResponseEntity<ResponseBean> getEntityInfo(Integer entityId){
        ResponseBean response = sysOntologyService.getEntityInfo(entityId);
        return ResponseEntity.status(response.getStatus()).body(response);
    }


    @ApiOperation("03 创建实体")
    @PostMapping("/entity-create")
    public ResponseEntity<ResponseBean> createEntity(String ontologyName){
        ResponseBean response = sysOntologyService.createEntity(ontologyName);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

     @ApiOperation("04 上传实体图标")
     @PostMapping(value = "/entity-pic")
     @ApiImplicitParam(name = "entityId",value = "实体id",paramType = "query",dataType = "int",defaultValue = "1")
     public ResponseEntity<ResponseBean> uploadEntityPic(Integer entityId, MultipartFile file) throws IOException {
         ResponseBean response = sysOntologyService.uploadEntityPic(entityId, file);
         return ResponseEntity.status(response.getStatus()).body(response);

     }

    @ApiOperation("05 删除实体")
    @DeleteMapping(value = "entity-del")
    @ApiImplicitParam(name = "entityId",value = "实体id",paramType = "query",dataType = "int",example = "1")
    public ResponseEntity<ResponseMessage> deleteEntity(Integer entityId){
        ResponseMessage response = sysOntologyService.deleteEntity(entityId);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

    @ApiOperation("06 编辑实体")
    @PutMapping(value = "entity-edit")
    public ResponseEntity<ResponseMessage> editEntity(EditEntityForm form){
        ResponseMessage response = sysOntologyService.editEntity(form);
        return ResponseEntity.status(response.getStatus()).body(response);
    }



}

